<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>人群分类</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>健康干预
            <small>人群分类</small>
        </h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>健康干预</el-breadcrumb-item>
            <el-breadcrumb-item>人群分类</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <el-input placeholder="档案号/姓名" v-model="pagination.queryString" style="width: 200px;"
                          class="filter-item"></el-input>
                <el-button type="info" plain icon="el-icon-search" @click="pagination.currentPage=1;findPage()" class="dalfBut">查询</el-button>
                <!--disabled值动态显示，默认为true,当选中复选框后值为false-->
                <el-button type="warning" icon="el-icon-delete" @click="deleteselections" :disabled="this.deleteIds.length===0">批量删除</el-button>
            </div>
            <el-table @selection-change="selections" border="true" size="small" current-row-key="id"
                      :data="dataList" stripe highlight-current-row>
                <el-table-column
                        type="selection"
                        width="40"
                        ref="multipleTable"
                >
                </el-table-column>
                <el-table-column prop="fileNumber" label="档案号" align="center"></el-table-column>
                <el-table-column prop="name" label="姓名" align="center"></el-table-column>
                <el-table-column label="性别" align="center" width="60">
                    <template slot-scope="scope">
                        <span>{{ scope.row.sex == '1' ? '男' : '女'}}</span>
                    </template>
                </el-table-column>
                <el-table-column prop="age" label="年龄" align="center" width="60"></el-table-column>
                <el-table-column prop="categoryStatus" label="状态" align="center" width="130"></el-table-column>
                <el-table-column prop="categoryStyles" label="人群分类" align="center" width="220"></el-table-column>
                <el-table-column prop="healthManagerName" label="健康管理师" align="center" width=""></el-table-column>
                <el-table-column label="操作" align="center" width="150">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">确认分类</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>

            <!--确认分类弹层-->
            <div class="add-form">
                <el-dialog title="健康管理师确认分类" :visible.sync="dialogFormVisible" v-if="dialogFormVisible">
                    <template>
                        <el-tabs v-model="activeName" type="card">
                            <el-tab-pane label="基本信息" name="first">
                                <el-form ref="dataAddForm" :model="formData" :rules="rules" label-position="right" label-width="100px">
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item :disabled="edit" label="档案号" prop="fileNumber">
                                                <el-input v-model="formData.fileNumber"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item :disabled="edit" label="姓名" prop="name">
                                                <el-input v-model="formData.name"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item :disabled="edit" label="性别" prop="sex">
                                                <el-select v-model="formData.sex">
                                                    <el-option label="不限" value="0"></el-option>
                                                    <el-option label="男" value="1"></el-option>
                                                    <el-option label="女" value="2"></el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item :disabled="edit" label="年龄" prop="age">
                                                <el-input v-model="formData.age"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="24">
                                            <el-form-item label="疾病史" prop="illnessHistory">
                                                <el-input v-model="formData.illnessHistory" type="textarea"></el-input>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="24">
                                            <el-form-item label="遗传史" prop="geneticHistory">
                                                <el-input v-model="formData.geneticHistory" type="geneticHistory"></el-input>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="24">
                                            <el-form-item label="手术史" prop=" surgeryHistory">
                                                <el-input v-model="formData.surgeryHistory" type="textarea"></el-input>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </el-tab-pane>
                            <el-tab-pane label="体检信息" name="second">
                                <div class="checkScrol">
                                    <table class="datatable">
                                        <thead>
                                        <tr>
                                            <th>选择</th>
                                            <th>项目编码</th>
                                            <th>项目名称</th>
                                            <th>项目说明</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr v-for="c in tableData">
                                            <td>
                                                <input :id="c.id" v-model="checkitemIds" type="checkbox" :value="c.id">
                                            </td>
                                            <td style=""><label :for="c.id">{{c.code}}</label></td>
                                            <td><label :for="c.id">{{c.name}}</label></td>
                                            <td><label :for="c.id">{{c.remark}}</label></td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </el-tab-pane>
                            <el-tab-pane label="评估结果" name="thrid">
                                <div class="checkScrol">
                                    <table class="datatable">
                                        <thead>
                                        <tr>
                                            <th>选择</th>
                                            <th>项目编码</th>
                                            <th>项目名称</th>
                                            <th>项目说明</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr v-for="c in tableData">
                                            <td>
                                                <input :id="c.id" v-model="checkitemIds" type="checkbox" :value="c.id">
                                            </td>
                                            <td style=""><label :for="c.id">{{c.code}}</label></td>
                                            <td><label :for="c.id">{{c.name}}</label></td>
                                            <td><label :for="c.id">{{c.remark}}</label></td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </el-tab-pane>
                            <el-tab-pane label="分类确认" name="forth">
                                <div class="checkScrol">
                                    <table class="datatable">
                                        <thead>
                                        <tr>
                                            <th>选择</th>
                                            <th>项目编码</th>
                                            <th>项目名称</th>
                                            <th>项目说明</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr v-for="c in tableData">
                                            <td>
                                                <input :id="c.id" v-model="checkitemIds" type="checkbox" :value="c.id">
                                            </td>
                                            <td style=""><label :for="c.id">{{c.code}}</label></td>
                                            <td><label :for="c.id">{{c.name}}</label></td>
                                            <td><label :for="c.id">{{c.remark}}</label></td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </el-tab-pane>
                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">确定</el-button>
                    </div>
                </el-dialog>
            </div>

        </div>
    </div>
</div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script>
    var vue = new Vue({
        el: '#app',
        data: {
            edit:true, //设置表单某项不能修改
            pagination: {//分页相关模型数据
                currentPage: 1,//当前页码
                pageSize: 10,//每页显示的记录数
                total: 0,//总记录数
                queryString: null//查询条件
            },
            dataList: [],//当前页要展示的分页列表数据
            formData: {},//表单数据
            dialogFormVisible: false,//增加表单是否可见
            dialogFormVisible4Edit: false,//编辑表单是否可见
            multipleSelection: [],// 当复选框选中后的行对象
            deleteIds: [],// 需要删除的id的数组
            rules: {//校验规则
                // name: [{required: true, message: '姓名为必填项', trigger: 'blur'}],
                // sex: [{required: true, message: '性别为必填项', trigger: 'blur'}],
                // idCard: [{required: true, message: '身份证号为必填项', trigger: 'blur'}],
                // phoneNumber: [{required: true, message: '电话号码为必填项', trigger: 'blur'}],
            }
        },
        //钩子函数，VUE对象初始化完成后自动执行
        created() {
            // 钩子函数为页面加载完成后执行,所以需要展示所有会员档案数据,所以调用findpage方法
            this.findPage()
        },
        methods: {
            // 设置日期在表格中的显示格式
            formatDate(row, column) {
                // 获取单元格数据
                let data = row[column.property]
                if(data == null) {
                    return null
                }
                let dt = new Date(data)
                return dt.getFullYear() + '-' + (dt.getMonth() + 1) + '-' + dt.getDate()
            },

            //权限不足提示方法(在操作后,因为权限不足问题,执行ajax的catch方法)
            // 'Error: Request failed with status code 403' 为security框架自动抛出的异常,固定写法
            errorOf403(r) {
                if (r == 'Error: Request failed with status code 403') {
                    // 如果返回的响应为改错误,则表示因权限不足,给出提示
                    this.$message.error("对不起,未拥有该操作权限");
                    return;
                } else {
                    // 如果不是上面错误,则表示是其他非权限问题的错误
                    this.$message.error("未知错误");
                    return;
                }
            },

            // 重置表单
            resetForm() {
                // 1.将添加表单数据设置为空,每次点击新建不会保留之前信息
                this.formData = {};
                // // 2 当每次弹出窗口时,将该表单格式化,不显示之前检验信息
                // if (this.$refs['dataAddForm'] != undefined) {
                //     this.$refs['dataAddForm'].resetFields();
                //也可以用clearValidate()方法,清除表单检验信息
                // this.$refs['dataAddForm'].clearValidate()
                // 也可以在表单中添加v-if="dialogFormVisible",表示每次重新加载一个新的表单
            },


            //分页查询会员
            /*
            页面加载完,翻页,点击查询按钮均会调用该方法,
            但是点击查询时,会先将pagination.currentPage=1,在执行该方法
            * */
            findPage() {
                /*
                1.首先需要请求参数,当前页,每页条数,查询条件,设置为json格式
                    从data中的pagination数据中获取
                * */
                var requestParm = {
                    currentPage: this.pagination.currentPage,
                    pageSize: this.pagination.pageSize,
                    queryString: this.pagination.queryString
                };
                /*
                2.发送ajax请求到/healthintervention/querypage.do
                * */
                axios.post("/healthIntervention/querypage.do", requestParm)
                /*
                    得到相应数据为pageresult对象的json格式数据
                    将pageresul的rows赋给dataList,展示查询到的数据
                    将pageresul的total赋给pagination中的total,展示查询到的总记录数
                    * */
                    .then((res) => {
                        this.dataList = res.data.rows;
                        this.pagination.total = res.data.total
                    }).catch((res) => {
                    // 3.如果权限不足或其他错误异常,则执行该catch方法,
                    // 并调用errorOf403方法,参数为res的响应数据
                    this.errorOf403(res);
                })
            },

            //新增会员
            // (1).弹出添加窗口
            handleCreate() {
                // 点击新建按钮,执行该方法,将dialogFormVisible设置为true,则显示新建窗口
                this.dialogFormVisible = true;
                // 需要每次点击表单,调用resetForm方法,重置新建窗口中的表单内容
                this.resetForm()
            },
            // (2).通过表单发送添加请求
            handleAdd() {
                /*
                点击确定按钮后,对表单所有想进行校验
                校验通过,发送ajax请求
                校验失败,弹出错误提示信息
                * */
                this.$refs['dataAddForm'].validate((valid) => {
                    // 1.如果valid为true,则证明表单项校验通过
                    if (valid) {
                        // 1.1. 发送ajsx请求到member/add.do,传递的数据为表单中数据,也就是formData
                        axios.post("/member/add.do", this.formData)
                        // 1.2. 返回的数据为result对象的json格式数据
                            .then((res) => {
                                // 1.3. 判断result中的flag如果为true,则弹出提示信息,并调用findpage方法重新查询数据
                                if (res.data.flag) {
                                    // 1.4. 如果flag为true,需要将添加窗口关闭,并调用findPage(),
                                    this.dialogFormVisible = false;
                                    // 1.4.1 在查询最新检查项数据
                                    this.findPage();
                                    // 1.4.2 在弹出成功提示框
                                    this.$message({
                                        // 因为后台在返回result对象时,已经在message中设置了提示信息
                                        message: res.data.message,
                                        type: "success"
                                    });

                                } else {
                                    // 1.5. 如果flag为false,则说明后台调用远程服务时失败,弹出错误信息
                                    // 该错误信息同样也是后台设置好的了
                                    this.$message.error(res.data.message)
                                }
                            })
                            .catch((res) => {
                                // 2.如果权限不足或其他错误异常,则执行该catch方法,
                                // 并调用errorOf403方法,参数为res的响应数据
                                this.errorOf403(res);
                            })
                    } else {
                        // 2.如果不为true,则表示表单填写有误,给出提示窗口,并直接返回false
                        this.$message.error("提交失败,表单项填写有误");
                        return false;
                    }
                })
            },





            //切换页码
            handleCurrentChange(currentPage) {
                /*
                每次切换页码后,需要从新查询检查项,需要将参数当前页赋值给pagination
                然后在调用findpage方法,此时该方法中的当前页数就位currentPage的值
                * */
                this.pagination.currentPage = currentPage;
                this.findPage()
            },

        }
    })
</script>
</html>